// pages/classActivities/classActivities.js
const host=getApp().host;
Page({

  /**
   * 页面的初始数据
   */
  data: {
    classify:'',
    name:'',
    date:'',
    time:'',
    addr:''
  },

  /**选择日期 */
  changeDate(e){
    this.setData({
      date:e.detail.value
    })
  },

  /**选择时间 */
  changeTime(e){
    this.setData({
      time:e.detail.value
    })
  },

  /**输入名称 */
  inputName(e){
    this.setData({
      name:e.detail.value
    })
  },

  /**输入地点 */
  inputAddr(e){
    this.setData({
      addr:e.detail.value
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.initClassify();
  },

  /**初始化班级 */
  initClassify(){
    this.setData({
      classify:wx.getStorageSync('userInfo').classifyName
    })
  },

  /**跳转 */
  toList(){
    wx.navigateTo({
      url: '/pages/classActiveList/classActiveList',
    })
  },


  /**提交申请 */
  submit(){
    wx.showLoading({
      title: '提交申请',
    })
    let info={
      classify:wx.getStorageSync('userInfo').classify,
      name:this.data.name,
      addr:this.data.addr,
      time:new Date(this.data.date+" "+this.data.time).getTime(),
      status:1
    }

    wx.request({
      url: host+'/client/moralClassify/add',
      method:'POST',
      data:info,
      header:{
        'content-type': 'application/x-www-form-urlencoded'
      },
      success:res=>{
        if(res.data.status.code==200){
          wx.showToast({
            title: '提交成功',
          },()=>{
            wx.navigateBack()
          })
        }
      },
      complete:()=>{
        wx.hideLoading()
      }
    })
  }
})